﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using QuanLyVanBanBUS;

public partial class QLVB_Admin_CapNhatLoaiNguoiDung : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        layMaLoaiNguoiDung();

        layTenLoaiNguoiDung();
    }

    protected void layMaLoaiNguoiDung()
    {
        string maLoaiNguoiDungURL = Request.QueryString["MaLoaiNguoiDung"];

        LoaiNguoiDungBUS lndBUS = new LoaiNguoiDungBUS();

        string maLoaiNguoiDung = lndBUS.layMaLoaiNguoiDung(maLoaiNguoiDungURL);

        txtMaLoaiNguoiDung.Text = maLoaiNguoiDung;
    }

    protected void layTenLoaiNguoiDung()
    {
        string maLoaiNguoiDungURL = Request.QueryString["MaLoaiNguoiDung"];

        LoaiNguoiDungBUS lndBUS = new LoaiNguoiDungBUS();

        string tenLoaiNguoiDung = lndBUS.layTenLoaiNguoiDung(maLoaiNguoiDungURL);

        txtTenLoaiNguoiDung.Text = tenLoaiNguoiDung;
    }

    protected void btnCapNhat_Click(object sender, EventArgs e)
    {
        LoaiNguoiDung lndDTO = new LoaiNguoiDung();
        lndDTO.MaLoaiNguoiDung = txtMaLoaiNguoiDung.Text.ToUpper();
        lndDTO.TenLoaiNguoiDung = txtTenLoaiNguoiDung.Text.ToUpper();

        //Kiem tra rong
        if (lndDTO.MaLoaiNguoiDung.ToString() == string.Empty)
        {
            Alert.Show("Ma loai nguoi dung khong duoc rong");
            return;
        }

        if (lndDTO.TenLoaiNguoiDung.ToString() == string.Empty)
        {
            Alert.Show("Ten loai nguoi dung khong duoc rong");
            return;
        }

        //Sua
        if (lndDTO.MaLoaiNguoiDung.ToString() != string.Empty && lndDTO.TenLoaiNguoiDung.ToString() != string.Empty)
        {
            LoaiNguoiDungBUS lndBUS = new LoaiNguoiDungBUS();

            string maLoaiNguoiDungURL = Request.QueryString["MaLoaiNguoiDung"];

            lndBUS.suaLoaiNguoiDung(lndDTO, maLoaiNguoiDungURL);

            Response.Redirect("ThamSoNguoiDung.aspx");
        }
    }

    protected void btnDong_Click(object sender, EventArgs e)
    {
        Response.Redirect("ThamSoNguoiDung.aspx");
    }
}